const dao = require('../../common/dao/transaction');
const api = require('../../common/api');

module.exports = {
    /*
     * 投注列表（含是否中奖）
     */
    transactionList: async function (ctx) {
        if (!api.isset(ctx.request.query, ["pageNo", "pageSize"])) {
            ctx.body = api.apiError("parameters is not enough!");
            return;
        }
        let by = {
            orderBy: {
                k: "a.blockNumber",
                v: "desc"
            },
        };
        let fields = [
            "a.transactionHash", "a.blockHash",
            "a.gasUsed", "a.blockNumber", "a.status",
            "b.timestamp", "a.from", "a.to", "a.value", "a.data",
        ];
        ctx.body = await dao.transactionList(ctx.request.query, fields, by).then(async (data) => {
            return api.apiExport(data, 0);
        }).catch((e) => {
            console.log(e);
            return api.apiError(e.toString());
        });
    },
};